package com.khyr.controller;

import com.aliyuncs.http.HttpRequest;
import com.khyr.entity.CareHistory;
import com.khyr.entity.CareOrderItem;
import com.khyr.entity.HisCareHistory;
import com.khyr.entity.HisRegistration;
import com.khyr.feign.UserFeign;
import com.khyr.service.NewCareService;
import com.khyr.vo.GetPatientAllMessageByPatientIdDto;
import com.khyr.vo.HisCareHVo;
import com.khyr.vo.R;
import com.khyr.vo.SaveCareOrderItemVo;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：Zhang
 * @date ：Created in 2025/3/14 15:37
 * @description：新开就诊
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/seeADoctor/NewCare")
public class NewCareController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserFeign userFeign;
    @Autowired
    private NewCareService newCareService;

    /**
     * @create by: Zr
     * @description: 待就诊信息，根据门诊和急诊和医生id查询
     * @create time: 2025/3/14 15:55
     * @param scheudlingType
     * @return java.lang.String
     */
    @GetMapping("/queryToBeSeenRegistration/{scheudlingType}")
    public R<List<HisRegistration>> queryToBeSeenRegistration(@PathVariable String scheudlingType){
        String token = request.getHeader("token");
        // 获取当前登录医生的id
        Long uId=userFeign.getUserInfo(token).getData().getUserId();
        return newCareService.queryToBeSeenRegistration(uId,scheudlingType);
    }
    /**
     * @create by: Zr
     * @description: 就诊中信息，根据门诊和急诊和医生id查询
     * @create time: 2025/3/14 15:55
     * @param scheudlingType
     * @return java.lang.String
     */
    @GetMapping("/queryVisitingRegistration/{scheudlingType}")
    public R<List<HisRegistration>> queryVisitingRegistration(@PathVariable String scheudlingType){
        String token = request.getHeader("token");
        // 获取当前登录医生的id
        Long uId=userFeign.getUserInfo(token).getData().getUserId();
        return newCareService.queryVisitingRegistration(scheudlingType,uId);
    }
    /**
     * @create by: Zr
     * @description: 就诊完成信息，根据门诊和急诊和医生id查询
     * @create time: 2025/3/14 16:13
     * @param scheudlingType
     * @return com.khyr.vo.R<java.util.List<com.khyr.entity.HisRegistration>>
     */
    @GetMapping("/queryVisitCompletedRegistration/{scheudlingType}")
    public R<List<HisRegistration>> queryVisitCompletedRegistration(@PathVariable String scheudlingType){
        String token = request.getHeader("token");
        // 获取当前登录医生的id
        Long uId=userFeign.getUserInfo(token).getData().getUserId();
        return newCareService.queryVisitCompletedRegistration(scheudlingType,uId);
    }
    /**
     * @create by: Zr
     * @description: 根据挂号流水编号，更改挂号单状态，并存入医生信息
     * @create time: 2025/3/14 16:23
     * @param regId
     * @return com.khyr.vo.R<java.lang.String>
     */
    @GetMapping("/receivePatient/{regId}")
    public R<String> receivePatient(@PathVariable String regId){
        String token = request.getHeader("token");
        // 获取当前登录医生的id和姓名
        Long uId=userFeign.getUserInfo(token).getData().getUserId();
        String name=userFeign.getUserInfo(token).getData().getUserName();
        return newCareService.receivePatient(regId,uId,name);
    }
    /**
     * @create by: Zr
     * @description: 根据患者id查询患者信息，档案，病例
     * @create time: 2025/3/14 16:47
     * @param patientId
     * @return com.khyr.vo.R<com.khyr.vo.GetPatientAllMessageByPatientIdDto>
     */
    @GetMapping("/getPatientAllMessageByPatientId/{patientId}")
    public R<GetPatientAllMessageByPatientIdDto> getPatientAllMessageByPatientId(@PathVariable String patientId){
        return newCareService.getPatientAllMessageByPatientId(patientId);
    }
    /**
     * @create by: Zr
     * @description: 根据挂号单号查询病例信息
     * @create time: 2025/3/14 17:05
     * @param regId
     * @return com.khyr.vo.R<com.khyr.entity.HisCareHistory>
     */
    @GetMapping("/getCareHistoryByRegId/{regId}")
    public R<HisCareHistory> getCareHistoryByRegId(@PathVariable String regId){
        return newCareService.getCareHistoryByRegId(regId);
    }
    /**
     * @create by: Zr
     * @description: 根据病例ID查询处方列表及详情
     * @create time: 2025/3/17 10:51
     * @param chId
     * @return com.khyr.vo.R<java.util.List<com.khyr.entity.HisCareHistory>>
     */
    @GetMapping("/queryCareOrdersByChId/{chId}")
    public R<List<SaveCareOrderItemVo>> queryCareOrdersByChId(@PathVariable String chId){
        return newCareService.queryCareOrdersByChId(chId);
    }
    /**
     * @create by: Zr
     * @description: 保存病例信息
     * @create time: 2025/3/14 17:21
     * @param careHistory
     * @return com.khyr.vo.R<java.lang.String>
     */
    @PostMapping("/saveCareHistory")
    public R<HisCareHistory> saveCareHistory(@RequestBody HisCareHVo careHistory){
        String token = request.getHeader("token");
        // 获取当前登录医生的id
        Long uId=userFeign.getUserInfo(token).getData().getUserId();
        return newCareService.saveCareHistory(careHistory,uId);
    }
    /**
     * @create by: Zr
     * @description: 保存处方信息
     * @create time: 2025/3/17 14:25
     * @param data
     * @return com.khyr.vo.R<com.khyr.vo.SaveCareOrderItemVo>
     */
    @PostMapping("/saveCareOrderItem")
    public R<SaveCareOrderItemVo> saveCareOrderItem(@RequestBody SaveCareOrderItemVo data){
        String token = request.getHeader("token");
        // 获取当前登录医生的id
        Long uId=userFeign.getUserInfo(token).getData().getUserId();
        return newCareService.saveCareOrderItem(data,uId);
    }
    /**
     * @create by: Zr
     * @description: 根据处方明细id-item_id删除处方明细，并将处方中的药品返回库存中
     * @create time: 2025/3/17 14:57
     * @param itemId
     * @return com.khyr.vo.R<java.lang.String>
     */
    @DeleteMapping("/deleteCareOrderItemById/{itemId}")
    public R<String> deleteCareOrderItemById(@PathVariable String itemId){
        return newCareService.deleteCareOrderItemById(itemId);
    }
    /**
     * @create by: Zr
     * @description: 根据挂号单号修改挂号状态为就诊完成
     * @create time: 2025/3/17 15:06
     * @param regId
     * @return com.khyr.vo.R<java.lang.String>
     */
    @GetMapping("/visitComplete/{regId}")
    public R<String> visitComplete(@PathVariable String regId){
        return newCareService.visitComplete(regId);
    }

}
